import { Select } from 'antd'
import { useEffect } from 'react'
import { getChannels, getList } from '@/store/actions/article'
import { useDispatch, useSelector } from 'react-redux'

const Channel = ({ value, onChange, style }) => {
  const dispatch = useDispatch()
  useEffect(() => {
    dispatch(getChannels())
  }, [])

  const channels = useSelector((state) => state.article.channels).map(
    (item) => {
      return {
        value: item.id,
        label: item.name,
      }
    }
  )

  return (
    <Select
      placeholder="请选择文章频道"
      style={style}
      options={channels}
      value={value}
      onChange={onChange}
    />
  )
}

export default Channel
